export default {
  namespaced: true, // 开启命名空间
  state: {
    userInfo: { customerInfo: {} },
    identityList: [],
    currentIdentity: {},
    token: "",
    sysAgentInfo: {},
  },
  getters: {
    hasLogin: (state, getters) => {
      return !!state.token;
    },
    getCustomerInfo: (state, getters) => {
      if (getters.hasLogin) {
        return state.userInfo.customerInfo;
      } else {
        return {};
      }
    },
    getIdentity(state) {
      return state.currentIdentity;
    },
    getIdentityList(state) {
      return state.identityList;
    },
    getSysAgentInfo(state) {
      return state.sysAgentInfo;
    },
  },
  mutations: {
    setCustomerInfo(state, userInfo) {
      state.userInfo.customerInfo = userInfo;
    },
    afterLogin(state, userInfo) {
      state.userInfo = userInfo;
    },
    setToken(state, token) {
      state.token = token;
    },
    loginOut(state) {
      state.token = "";
      state.userInfo = {};
    },
    //设置用户身份列表
    setIdentityList(state, list) {
      state.identityList = list;
    },
    setCurrentIdentity(state, currentIdentity) {
      state.currentIdentity = currentIdentity;
    },
    setSysAgentInfo(state, sysAgentInfo) {
      state.sysAgentInfo = sysAgentInfo;
    },
  },
  actions: {
    loginOut({ commit }) {
      commit("loginOut");
    },
  },
};
